import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:ball_lion/widgets/loading/shimmer_loading_widget.dart';

class QsImage extends StatelessWidget {
  const QsImage(
      {super.key,
      required this.imageUrl,
      this.width,
      this.height,
      this.fit = BoxFit.cover,
      this.placeholder,
      this.errorWidget,
      this.radius,
      this.shimmer = true,
      this.shape});

  final String? imageUrl;
  final double? width;
  final double? height;
  final double? radius;
  final BoxFit fit;
  final Widget? placeholder;
  final Widget? errorWidget;
  final BoxShape? shape;
  final bool shimmer;

  @override
  Widget build(BuildContext context) {
    if (shimmer && imageUrl == null) {
      return ShimmerLoading(
        width: width ?? 10,
        height: height ?? 10,
        radius: radius ?? 0,
      );
    } else {
      return Container(
        clipBehavior: Clip.antiAlias,
        decoration: BoxDecoration(
            shape: shape ?? BoxShape.rectangle,
            borderRadius: shape != BoxShape.circle
                ? BorderRadius.circular(radius ?? 0)
                : null),
        child: CachedNetworkImage(
          imageUrl: imageUrl ?? "",
          width: width,
          height: height,
          fit: fit,
          placeholder: (context, url) => placeholder ?? Container(),
          errorWidget: (context, url, error) => errorWidget ?? Container(),
        ),
      );
    }
  }
}
